/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisfo.astacala.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author arif
 */
public class UtilPasswordEncryptor {

    private static UtilPasswordEncryptor passwordEncryptor;

    public static UtilPasswordEncryptor getInstance() {
        if (passwordEncryptor == null) {
            passwordEncryptor = new UtilPasswordEncryptor();
        }
        return passwordEncryptor;
    }

    public String encryptPassword(String password) {
        StringBuilder sb = new StringBuilder();
        sb.append("");
        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(password.getBytes());

            byte byteData[] = md.digest();
            
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

//            System.out.println("Hex format : " + sb.toString());            
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(UtilPasswordEncryptor.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sb.toString();
    }

    public static void main(String args[]) {
        UtilPasswordEncryptor.getInstance().encryptPassword("a001pr");
    }
}
